package com.thinkit.bigdata.core.util;

import org.apache.commons.lang.ArrayUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 数组操作工具类
 *
 * @author huangyong
 * @since 1.0
 */
public class ArrayUtil {

    /**
     * String字符串转成List<Long>数据格式
     * String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
     *
     * @param strArr -
     * @return -
     */
    public static List<Long> stringToLongList(String strArr) {
        return Arrays.stream(strArr.split(","))
                .map(s -> Long.parseLong(s.trim()))
                .collect(Collectors.toList());
    }

    /**
     * 判断数组是否非空
     */
    public static boolean isNotEmpty(Object[] array) {
        return !ArrayUtils.isEmpty(array);
    }

    /**
     * 判断数组是否为空
     */
    public static boolean isEmpty(Object[] array) {
        return ArrayUtils.isEmpty(array);
    }

    /**
     * 连接数组
     */
    public static Object[] concat(Object[] array1, Object[] array2) {
        return ArrayUtils.addAll(array1, array2);
    }

    /**
     * java8去重
     *
     */
    private static Collection<? extends String> getNoDuplicate4(List<String> datas) {
        return datas.stream().distinct().collect(Collectors.toList());
    }

    /**
     * 判断对象是否在数组中
     */
    public static <T> boolean contains(T[] array, T obj) {
        return ArrayUtils.contains(array, obj);
    }

    public static void main(String[] args) {
        String[] list = {"mand","yueh","wewr","kore","minn","engl","japa","fren","germ","russ","arab","zaan","zaka","zala","hasc"};
        boolean bool = contains(list, "mand");
        System.out.println(bool);
    }
}
